Add general doccomments
authorPierre Krieger <pierre.krieger1708@gmail.com>
Tue, 21 Oct 2014 14:38:29 +0000 (16:38 +0200)
committerPierre Krieger <pierre.krieger1708@gmail.com>
Tue, 21 Oct 2014 14:38:29 +0000 (16:38 +0200)
src/cargo/core/dependency.rs
src/cargo/core/manifest.rs
src/cargo/core/package.rs
src/cargo/core/package_id.rs
src/cargo/core/registry.rs
src/cargo/core/resolver.rs
src/cargo/core/source.rs
src/cargo/core/summary.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_fetch.rs

index fd3e5b961531f03b7016e3d844b29273269083e2..2585d6e34058628af21e788072eb1d93c0c2464b 100644 (file)
@@ -2,6 +2,7 @@ use core::{SourceId,Summary};
 use semver::VersionReq;
 use util::CargoResult;
 
+/// Informations about a dependency requested by a Cargo manifest.
 #[deriving(PartialEq,Clone,Show)]
 pub struct Dependency {
     name: String,
@@ -16,6 +17,16 @@ pub struct Dependency {
 }
 
 impl Dependency {
+    /// Attempt to create a `Dependency` from an entry in the manifest.
+    ///
+    /// ## Example
+    ///
+    /// ```
+    /// use cargo::core::SourceId;
+    /// use cargo::core::Dependency;
+    ///
+    /// Dependency::parse("color", Some("1.*"), SourceId::for_central())
+    /// ```
     pub fn parse(name: &str,
                  version: Option<&str>,
                  source_id: &SourceId) -> CargoResult<Dependency> {
@@ -44,6 +55,7 @@ impl Dependency {
         }
     }
 
+    /// Returns the version of the dependency that is being requested.
     pub fn get_version_req(&self) -> &VersionReq {
         &self.req
     }
@@ -52,6 +64,7 @@ impl Dependency {
         self.name.as_slice()
     }
 
+    /// Returns the place where this dependency must be searched for.
     pub fn get_source_id(&self) -> &SourceId {
         &self.source_id
     }
@@ -61,26 +74,33 @@ impl Dependency {
         self
     }
 
+    /// Sets the list of features requested for the package.
     pub fn features(mut self, features: Vec<String>) -> Dependency {
         self.features = features;
         self
     }
 
+    /// Sets whether the dependency requests default features of the package.
     pub fn default_features(mut self, default_features: bool) -> Dependency {
         self.default_features = default_features;
         self
     }
 
+    /// Sets whether the dependency is optional.
     pub fn optional(mut self, optional: bool) -> Dependency {
         self.optional = optional;
         self
     }
 
+    /// Returns false if the dependency is only used to build the local package.
     pub fn is_transitive(&self) -> bool { self.transitive }
     pub fn is_optional(&self) -> bool { self.optional }
+    /// Returns true if the default features of the dependency are requested.
     pub fn uses_default_features(&self) -> bool { self.default_features }
+    /// Returns the list of features that are requested by the dependency.
     pub fn get_features(&self) -> &[String] { self.features.as_slice() }
 
+    /// Returns true if the package (`sum`) can fulfill this dependency request.
     pub fn matches(&self, sum: &Summary) -> bool {
         debug!("matches; self={}; summary={}", self, sum);
         debug!("         a={}; b={}", self.source_id, sum.get_source_id());
index ac3629eb49a619ccb8e83a372565e7e6393bf69e..e274dbbc260a79ce7b080df4c1bb0e883d09549c 100644 (file)
@@ -14,6 +14,7 @@ use core::package_id::Metadata;
 use core::dependency::SerializedDependency;
 use util::{CargoResult, human};
 
+/// Contains all the informations about a package, as loaded from a Cargo.toml.
 #[deriving(PartialEq,Clone)]
 pub struct Manifest {
     summary: Summary,
@@ -89,6 +90,7 @@ impl LibKind {
         strings.iter().map(|s| LibKind::from_str(s.as_slice())).collect()
     }
 
+    /// Returns the argument suitable for `--crate-type` to pass to rustc.
     pub fn crate_type(&self) -> &'static str {
         match *self {
             Lib => "lib",
@@ -303,6 +305,7 @@ impl<H: hash::Writer> hash::Hash<H> for Profile {
     }
 }
 
+/// Informations about a binary, a library, an example, etc. that is part of the package.
 #[deriving(Clone, Hash, PartialEq)]
 pub struct Target {
     kind: TargetKind,
@@ -399,6 +402,7 @@ impl Manifest {
         &self.doc_dir
     }
 
+    /// Returns a list of all the potential `SourceId`s of the dependencies.
     pub fn get_source_ids(&self) -> &[SourceId] {
         self.sources.as_slice()
     }
@@ -520,6 +524,7 @@ impl Target {
         }
     }
 
+    /// Returns true for binary, bench, tests and examples.
     pub fn is_bin(&self) -> bool {
         match self.kind {
             BinTarget => true,
@@ -535,6 +540,7 @@ impl Target {
         self.metadata.as_ref()
     }
 
+    /// Returns the arguments suitable for `--crate-type` to pass to rustc.
     pub fn rustc_crate_types(&self) -> Vec<&'static str> {
         match self.kind {
             LibTarget(ref kinds) => {
index fb41ee1a36b48d57281ba27feff88bbbfbf08918..f0e65e7d88936f7b9ef0bd8fd7b9fcda2f969837 100644 (file)
@@ -15,6 +15,9 @@ use util::{CargoResult, graph};
 use serialize::{Encoder,Encodable};
 use core::source::{SourceId, Source};
 
+/// Informations about a package that is available somewhere in the file system.
+///
+/// A package is a `Cargo.toml` file, plus all the files that are part of it.
 // TODO: Is manifest_path a relic?
 #[deriving(Clone)]
 pub struct Package {
index e5e657677369a307c9a938fa74a0a742245be605..855272e96eaa299abcbd75b33b33e9734fc190f6 100644 (file)
@@ -9,6 +9,7 @@ use regex::Regex;
 use util::{CargoResult, CargoError, short_hash, ToSemver};
 use core::source::SourceId;
 
+/// Identifier for a specific version of a package in a specific source.
 #[deriving(Clone, PartialEq, PartialOrd, Ord)]
 pub struct PackageId {
     name: String,
index 5d95bcb157ca83efc5be594d228bc7ce371f5f8c..007cf4b76253fcd53fd359f2926f913461268766 100644 (file)
@@ -3,7 +3,11 @@ use std::collections::HashSet;
 use core::{Source, SourceId, SourceMap, Summary, Dependency, PackageId, Package};
 use util::{CargoResult, ChainError, Config, human, profile};
 
+/// Source of informations about a group of packages.
+///
+/// See also `core::Source`.
 pub trait Registry {
+    /// Attempt to find the packages that match a dependency request.
     fn query(&mut self, name: &Dependency) -> CargoResult<Vec<Summary>>;
 }
 
index 388220d2800042e3e06e618557bc278eb1625c86..2e846e3151bb94002260cf3fca65223b4834aab7 100644 (file)
@@ -11,6 +11,7 @@ use util::{CargoResult, Graph, human, internal, ChainError};
 use util::profile;
 use util::graph::{Nodes, Edges};
 
+/// Result of the `resolve` function.
 #[deriving(PartialEq, Eq)]
 pub struct Resolve {
     graph: Graph<PackageId>,
@@ -301,6 +302,7 @@ impl<'a, R: Registry> Context<'a, R> {
     }
 }
 
+/// Builds the list of all packages required to build the first argument.
 pub fn resolve<R: Registry>(summary: &Summary, method: ResolveMethod,
                             registry: &mut R) -> CargoResult<Resolve> {
     log!(5, "resolve; summary={}", summary);
index e89eefca875c1d9ca5d6dfeed315ecabd2431bde..423b5d9a3be88f0d79a8ed636355557891f5ccad 100644 (file)
@@ -56,6 +56,7 @@ pub enum SourceKind {
 
 type Error = Box<CargoError + Send>;
 
+/// Unique identifier for a source of packages.
 #[deriving(Clone, Eq)]
 pub struct SourceId {
     pub url: Url,
@@ -158,6 +159,16 @@ impl SourceId {
         SourceId { kind: kind, url: url, precise: None }
     }
 
+    /// Parses a source URL and returns the corresponding ID.
+    ///
+    /// ## Example
+    ///
+    /// ```
+    /// use cargo::core::SourceId;
+    /// SourceId::from_url("git+https://github.com/alexcrichton/\
+    ///                     libssh2-static-sys#80e71a3021618eb05\
+    ///                     656c58fb7c5ef5f12bc747f".to_string())
+    /// ```
     pub fn from_url(string: String) -> SourceId {
         let mut parts = string.as_slice().splitn(1, '+');
         let kind = parts.next().unwrap();
@@ -235,6 +246,10 @@ impl SourceId {
         SourceId::new(RegistryKind, url.clone())
     }
 
+    /// Returns the `SourceId` corresponding to the main repository.
+    /// 
+    /// This is the main cargo registry by default, but it can be overridden in
+    /// a `.cargo/config`.
     pub fn for_central() -> CargoResult<SourceId> {
         Ok(SourceId::for_registry(&try!(RegistrySource::url())))
     }
@@ -254,6 +269,7 @@ impl SourceId {
         }
     }
 
+    /// Creates an implementation of `Source` corresponding to this ID.
     pub fn load<'a>(&self, config: &'a mut Config) -> Box<Source+'a> {
         log!(5, "loading SourceId; {}", self);
         match self.kind {
@@ -334,6 +350,7 @@ impl<'a> SourceMap<'a> {
     }
 }
 
+/// List of `Source` implementors. `SourceSet` itself implements `Source`.
 pub struct SourceSet<'a> {
     sources: Vec<Box<Source+'a>>
 }
index 582f988f0016e3a8aef594f86f476e60469caf0b..b794f8db42755199bd888e9b8bd19754dee1394e 100644 (file)
@@ -5,6 +5,8 @@ use core::{Dependency, PackageId, SourceId};
 
 use util::{CargoResult, human};
 
+/// Subset of a `Manifest`. Contains only the most important informations about a package.
+///
 /// Summaries are cloned, and should not be mutated after creation
 #[deriving(Show,Clone,PartialEq)]
 pub struct Summary {
index 01f10f6a760ff2d6431a6afa99beb6b8d22b1b66..438947a4bb4396b29a6d1f6991dbbd5c4b094758 100644 (file)
@@ -33,11 +33,15 @@ use sources::{PathSource};
 use util::config::{Config, ConfigValue};
 use util::{CargoResult, Wrap, config, internal, human, ChainError, profile};
 
+/// Contains informations about how a package should be compiled.
 pub struct CompileOptions<'a> {
     pub env: &'a str,
     pub shell: &'a mut MultiShell<'a>,
+    /// Number of concurrent jobs to use.
     pub jobs: Option<uint>,
+    /// The target platform to compile for (example: `i686-unknown-linux-gnu`).
     pub target: Option<&'a str>,
+    /// True if dev-dependencies must be compiled.
     pub dev_deps: bool,
     pub features: &'a [String],
     pub no_default_features: bool,
index 310b18ca59796ce1c2f3ba1bd6a620d416c740f1..e8820df8b0f003398cbb6ec93b6c241f4bb2c052 100644 (file)
@@ -9,6 +9,7 @@ use sources::PathSource;
 use util::{CargoResult, Config};
 use util::profile;
 
+/// Executes `cargo fetch`.
 pub fn fetch(manifest_path: &Path,
              shell: &mut MultiShell) -> CargoResult<()> {
     let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
@@ -21,6 +22,10 @@ pub fn fetch(manifest_path: &Path,
     Ok(())
 }
 
+/// Finds all the packages required to compile the specified `Package`,
+/// and loads them in the `PackageRegistry`.
+///
+/// Also write the `Cargo.lock` file with the results.
 pub fn resolve_and_fetch(registry: &mut PackageRegistry, package: &Package)
                          -> CargoResult<Resolve> {
     let _p = profile::start("resolve and fetch...");